from pyquery import PyQuery as pq
import requests
from redis import StrictRedis
import os


print('windows直接复制链接会自动把\改为/的')
#dizhi=input('请输入你要保存的文件位置(如F:/......):')
#cu=dizhi.replace("\\",'/')


o=1

headers={
    'user-agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 SE 2.X MetaSr 1.0'

}


def xpan(canshu):
    try:
        url = 'https://www.doutula.com/photo/list/?page=' + str(canshu)
        sp = requests.get(url, headers=headers).text

        doc=pq(sp)
        item=doc('.col-xs-6 img').items()

        for i in item:
            cu=i.attr('data-original')



            #r(cu,'F:/斗图的/%s.jpg'%u)
           # u+=1
            #print('当前已保存%d张'%u)
            #print(cu)
            redis = StrictRedis(host='172.18.200.5', port=6379, db=1, password='')
            redis.sadd('斗图网全部的', cu)

    except Exception as e:

       print('出现错误',e.args)
print('请输入你要从第几页爬爬到第几页')
a=int(input('请输入你要从第几页开始爬:'))
b=int(input('请输入你要截止页数:'))
print('正在爬取链接并保存到redis数据库中请稍等........')
for i in range(a,b):

   xpan(i+1)
print('ok了')



